<?php

namespace App\Http\Validate\OpenShop\InvestmentPromotion;

use App\Http\Validate\BaseValidate;
use Illuminate\Validation\ValidationException;


/**
 * [ open_shop_preparation_order_refund_stream 筹备订单 ] - 校验规则
 *
 * @SpaceDesignPreparationRefundValidate
 * @package App\Http\Controllers
 * @date 2022/04/15 06:51:44
 * @author huang <473842579@qq.com>
 */
class SpaceDesignPreparationRefundValidate extends BaseValidate
{

    public static function registerValidateRules(): void
    {
        // TODO: Implement registerValidateRules() method.
    }

    /**
     * 预处理参数
     *
     * @param array $data
     * @return array
     */
    public static function beforeValidate(array $data): array
    {
        $data = collect($data)->filter(function ($v) {
            if ($v === "") {
                return false;
            }
            return true;
        })->toArray();
        return parent::beforeValidate($data); // TODO: Change the autogenerated stub
    }

    /**
     * 获取规则信息
     *
     * @param array $fields
     * @return string[]
     */
    public static function getRules(array $fields = []): array
    {
        return self::getActuallyRules([
            'preparationNo' => 'required|string',
            'type'          => 'required|integer',
            'refundMoney'   => 'required|integer',
            'remark'        => ''
        ], $fields);
    }

    public static array $attributes = [
        'preparationNo' => '筹备订单号',
        'type'          => '退款类型',
        'refundMoney'   => '退款金额',
        'remark'        => '备注'
    ];

    /**
     * 创建校验
     *
     * @param array $requestParams
     * @return array
     * @throws ValidationException
     */
    public static function refundValidate(array $requestParams): array
    {
        return self::baseValidate(
            $requestParams,
            collect(self::getRules())->keys()->toArray()
        );
    }

    /**
     * 更新校验
     *
     * @param array $requestParams
     * @return array
     * @throws ValidationException
     */
    public static function updateValidate(array $requestParams): array
    {
        return self::baseValidate($requestParams, array_keys(self::getRules()));
    }

    /**
     * 删除校验
     *
     * @param array $requestParams
     * @return array
     */
    public static function delValidate(array $requestParams): array
    {
        return self::getRequestParams($requestParams, array_keys(self::getRules()));
    }

    /**
     * 状态校验
     *
     * @param array $requestParams
     * @return array
     */
    public static function statusValidate(array $requestParams): array
    {
        return self::getRequestParams($requestParams, array_keys(self::getRules()));
    }


}
